﻿using AutoMapper;
using FoodModel;
using J.FoodManageSet.Application.Command.TasteCommand;
using J.FoodRepository.InterFace;
using MediatR;

namespace J.FoodManageSet.Application.CommandHandler.TasteCommandHandler
{
    /// <summary>
    /// 口味添加
    /// </summary>
    public class TasteAddCommandHandler : IRequestHandler<TasteAddCommand, int>
    {
        private readonly ITasteRepository _tasteRepository;
        private readonly IMapper _mapper;

        public TasteAddCommandHandler(ITasteRepository tasteRepository,IMapper mapper)
        {
            _tasteRepository = tasteRepository;
            _mapper = mapper;
        }
        public async Task<int> Handle(TasteAddCommand request, CancellationToken cancellationToken)
        {
            TasteModel model= _mapper.Map<TasteModel>(request);
            var list = await _tasteRepository.TasteAdd(model);
            return list;
        }
    }
}
